{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "    Platt 的 SMO 算法\n",
    "    * 工作原理\n",
    "        每次循环中选择两个 alpha 进行优化处理。一旦找到一对合适的alpha，那么就增大一个同时减小另一个。\n",
    "        alpha(需要符合两个条件：1、两个alpha必须在间隔边界之外。2、两个alpha还没经过去间化处理，或者不在边界上)\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# SMO 算法中的辅助函数\n",
    "from numpy import * \n",
    "\n",
    "def loadDataSet(fileName):\n",
    "    dataMat = []; labelMat = []\n",
    "    fr = open(fileName)\n",
    "    for line in fr.readlines():\n",
    "        lineArr = line.strip().split('\\t')\n",
    "        dataMat.append([float(lineArr[0]), float(lineArr[1])])\n",
    "        labelMat.append(float(lineArr[2]))\n",
    "    return dataMat, labelMat\n",
    "\n",
    "\n",
    "def selectJrand(i, m):\n",
    "    j = i \n",
    "    while (j==i):\n",
    "        j = int(random.uniform(0, m))\n",
    "    return j \n",
    "\n",
    "\n",
    "def clipAlpha(aj, H, L):\n",
    "    if aj > H:\n",
    "        aj = H\n",
    "    if L > aj:\n",
    "        aj = L\n",
    "    return aj \n",
    "\n",
    "\n",
    "dataMat, labelMat = loadDataSet('testSet.txt')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "    SMO 函数伪代码\n",
    "    创建一个 alpha 向量并将其初始化为 0 向量\n",
    "    当迭代次数小于最大迭代次数时（\n",
    "\"\"\""
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
